﻿using System;
using System.Collections.Generic;
using System.Data;
using nkstdgia.common.ThamDinhGia.BusinessObjects;

namespace nkstdgia.common.ThamDinhGia.DataAccess
{
    public class CONG_TRINH_XAY_DUNGDA
    {
        #region ***** Init Methods *****

        public CONG_TRINH_XAY_DUNGDA()
        {
        }

        #endregion ***** Init Methods *****

        #region ***** Get Methods *****

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public CONG_TRINH_XAY_DUNG Populate(IDataReader myReader)
        {
            CONG_TRINH_XAY_DUNG obj = new CONG_TRINH_XAY_DUNG();
            obj.MA_HO_SO = (Int64)myReader["MA_HO_SO"];
            obj.LOAI_NHA = (Int64)myReader["LOAI_NHA"];
            obj.NOI_DUNG_LOAI_NHA = myReader["NOI_DUNG_LOAI_NHA"] != DBNull.Value ? (string)myReader["NOI_DUNG_LOAI_NHA"] : "";
            obj.LOAI_CAP_NHA = (Int64)myReader["LOAI_CAP_NHA"];
            obj.HUONG_NHA = (Int64)myReader["HUONG_NHA"];
            obj.GIAY_PHEP_XAY_DUNG = myReader["GIAY_PHEP_XAY_DUNG"] != DBNull.Value ? (string)myReader["GIAY_PHEP_XAY_DUNG"] : "";
            obj.DIEN_TICH_XD_CONG_NHAN = myReader["DIEN_TICH_XD_CONG_NHAN"] != DBNull.Value ? (double)myReader["DIEN_TICH_XD_CONG_NHAN"] : 0.0;
            obj.DIEN_TICH_XD_KHONG_CONG_NHAN = (double)myReader["DIEN_TICH_XD_KHONG_CONG_NHAN"];
            obj.NAM_XAY_DUNG = myReader["NAM_XAY_DUNG"] != DBNull.Value ? (DateTime)myReader["NAM_XAY_DUNG"] : DateTime.Now;
            obj.SO_NAM_SU_DUNG = myReader["SO_NAM_SU_DUNG"] != DBNull.Value ? (double)myReader["SO_NAM_SU_DUNG"] : 0.0;
            obj.DON_GIA_XAY_DUNG = myReader["DON_GIA_XAY_DUNG"] != DBNull.Value ? (double)myReader["DON_GIA_XAY_DUNG"] : 0.0;
            obj.TUOI_DOI_KINH_TE = myReader["TUOI_DOI_KINH_TE"] != DBNull.Value ? (double)myReader["TUOI_DOI_KINH_TE"] : 0.0;
            obj.GIA_TRI_CONG_TRINH = myReader["GIA_TRI_CONG_TRINH"] != DBNull.Value ? (double)myReader["GIA_TRI_CONG_TRINH"] : 0.0;
            obj.SO_LAN_SUA_CHUA = (int)myReader["SO_LAN_SUA_CHUA"];
            return obj;
        }

        /// <summary>
        /// Get CONG_TRINH_XAY_DUNG by ma_ho_so
        /// </summary>
        /// <param name="ma_ho_so">MA_HO_SO</param>
        /// <returns>CONG_TRINH_XAY_DUNG</returns>
        public CONG_TRINH_XAY_DUNG GetByMA_HO_SO(Int64 ma_ho_so)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_CONG_TRINH_XAY_DUNG_GetByMA_HO_SO", Data.CreateParameter("MA_HO_SO", ma_ho_so)))
            {
                if (reader.Read())
                {
                    return Populate(reader);
                }
                return null;
            }
        }

        /// <summary>
        /// Get all of CONG_TRINH_XAY_DUNG
        /// </summary>
        /// <returns>List<<CONG_TRINH_XAY_DUNG>></returns>
        public List<CONG_TRINH_XAY_DUNG> GetList()
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_CONG_TRINH_XAY_DUNG_Get"))
            {
                List<CONG_TRINH_XAY_DUNG> list = new List<CONG_TRINH_XAY_DUNG>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of CONG_TRINH_XAY_DUNG
        /// </summary>
        /// <returns>DataSet</returns>
        public DataSet GetDataSet()
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_CONG_TRINH_XAY_DUNG_Get");
        }

        /// <summary>
        /// Get all of CONG_TRINH_XAY_DUNG paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>List<<CONG_TRINH_XAY_DUNG>></returns>
        public List<CONG_TRINH_XAY_DUNG> GetListPaged(int recperpage, int pageindex)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_CONG_TRINH_XAY_DUNG_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex)))
            {
                List<CONG_TRINH_XAY_DUNG> list = new List<CONG_TRINH_XAY_DUNG>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of CONG_TRINH_XAY_DUNG paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>DataSet</returns>
        public DataSet GetDataSetPaged(int recperpage, int pageindex)
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_CONG_TRINH_XAY_DUNG_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex));
        }

        #endregion ***** Get Methods *****

        #region ***** Add Update Delete Methods *****

        /// <summary>
        /// Add a new CONG_TRINH_XAY_DUNG within CONG_TRINH_XAY_DUNG database table
        /// </summary>
        /// <param name="obj">CONG_TRINH_XAY_DUNG</param>
        /// <returns>key of table</returns>
        public long Add(CONG_TRINH_XAY_DUNG obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_CONG_TRINH_XAY_DUNG_Add"
                            , Data.CreateParameter("MA_HO_SO", obj.MA_HO_SO)
                            , Data.CreateParameter("LOAI_NHA", obj.LOAI_NHA)
                            , Data.CreateParameter("NOI_DUNG_LOAI_NHA", obj.NOI_DUNG_LOAI_NHA)
                            , Data.CreateParameter("LOAI_CAP_NHA", obj.LOAI_CAP_NHA)
                            , Data.CreateParameter("HUONG_NHA", obj.HUONG_NHA)
                            , Data.CreateParameter("GIAY_PHEP_XAY_DUNG", obj.GIAY_PHEP_XAY_DUNG)
                            , Data.CreateParameter("DIEN_TICH_XD_CONG_NHAN", obj.DIEN_TICH_XD_CONG_NHAN)
                            , Data.CreateParameter("DIEN_TICH_XD_KHONG_CONG_NHAN", obj.DIEN_TICH_XD_KHONG_CONG_NHAN)
                            , Data.CreateParameter("NAM_XAY_DUNG", obj.NAM_XAY_DUNG)
                            , Data.CreateParameter("SO_NAM_SU_DUNG", obj.SO_NAM_SU_DUNG)
                            , Data.CreateParameter("DON_GIA_XAY_DUNG", obj.DON_GIA_XAY_DUNG)
                            , Data.CreateParameter("TUOI_DOI_KINH_TE", obj.TUOI_DOI_KINH_TE)
                            , Data.CreateParameter("GIA_TRI_CONG_TRINH", obj.GIA_TRI_CONG_TRINH)
                            , Data.CreateParameter("SO_LAN_SUA_CHUA", obj.SO_LAN_SUA_CHUA)
            );
            return obj.MA_HO_SO;
        }

        /// <summary>
        /// updates the specified CONG_TRINH_XAY_DUNG
        /// </summary>
        /// <param name="obj">CONG_TRINH_XAY_DUNG</param>
        /// <returns></returns>
        public void Update(CONG_TRINH_XAY_DUNG obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_CONG_TRINH_XAY_DUNG_Update"
                            , Data.CreateParameter("MA_HO_SO", obj.MA_HO_SO)
                            , Data.CreateParameter("LOAI_NHA", obj.LOAI_NHA)
                            , Data.CreateParameter("NOI_DUNG_LOAI_NHA", obj.NOI_DUNG_LOAI_NHA)
                            , Data.CreateParameter("LOAI_CAP_NHA", obj.LOAI_CAP_NHA)
                            , Data.CreateParameter("HUONG_NHA", obj.HUONG_NHA)
                            , Data.CreateParameter("GIAY_PHEP_XAY_DUNG", obj.GIAY_PHEP_XAY_DUNG)
                            , Data.CreateParameter("DIEN_TICH_XD_CONG_NHAN", obj.DIEN_TICH_XD_CONG_NHAN)
                            , Data.CreateParameter("DIEN_TICH_XD_KHONG_CONG_NHAN", obj.DIEN_TICH_XD_KHONG_CONG_NHAN)
                            , Data.CreateParameter("NAM_XAY_DUNG", obj.NAM_XAY_DUNG)
                            , Data.CreateParameter("SO_NAM_SU_DUNG", obj.SO_NAM_SU_DUNG)
                            , Data.CreateParameter("DON_GIA_XAY_DUNG", obj.DON_GIA_XAY_DUNG)
                            , Data.CreateParameter("TUOI_DOI_KINH_TE", obj.TUOI_DOI_KINH_TE)
                            , Data.CreateParameter("GIA_TRI_CONG_TRINH", obj.GIA_TRI_CONG_TRINH)
                            , Data.CreateParameter("SO_LAN_SUA_CHUA", obj.SO_LAN_SUA_CHUA)
            );
        }

        /// <summary>
        /// Delete the specified CONG_TRINH_XAY_DUNG
        /// </summary>
        /// <param name="ma_ho_so">MA_HO_SO</param>
        /// <returns></returns>
        public void Delete(Int64 ma_ho_so)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_CONG_TRINH_XAY_DUNG_Delete", Data.CreateParameter("MA_HO_SO", ma_ho_so));
        }

        #endregion ***** Add Update Delete Methods *****
    }
}